Skip to content

Conversation

richvigorito
Copy link

Check for tree equivalence

Description of Change

We recursively traverse both trees simultaneously:

If both nodes are NULL, return true.
If only one of them is NULL, return false.
Compare the current node values. If they differ, return false.
Recursively check the left children and right children. Both must be true for the trees to be the same.

This naturally follows the definition of two identical trees.

References

Checklist

  • Added description of change
  • Added file name matches
  • Added tests and example, test must pass. CLICK HERE to run in leetcode
  • Relevant documentation/comments is changed or added
  • PR title follows semantic
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

Check for tree equivalence
@github-actions github-actions bot added the Leetcode folder changes Changes to Leetcode folder. Known CI issues. label Sep 14, 2025
Copy link
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Leetcode folder changes Changes to Leetcode folder. Known CI issues. Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant